package org.rency.crawler.fetch.converter.impl;

import org.rency.common.utils.enums.YesNoEnum;
import org.rency.crawler.common.enums.FirLevelKind;
import org.rency.crawler.common.enums.SecLevelKind;
import org.rency.crawler.dal.entity.MetaResourceDO;
import org.rency.crawler.domain.vo.MetaResourceDomain;
import org.rency.crawler.fetch.converter.AbstractDomainConvertor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * 描述: ${TODO}<br>
 * 最近修改时间:2017/11/20 18:05<br>
 *
 * @author CaiyuRen
 * @version V1.0
 * @since 2017/11/20 18:05
 */
@Component
public class MetaResourceDomainConvertor extends AbstractDomainConvertor<MetaResourceDomain, MetaResourceDO> {

  @Override
  public MetaResourceDomain convertDomain(MetaResourceDO entity) {
    if(entity == null){
      return null;
    }
    MetaResourceDomain domain = new MetaResourceDomain();
    BeanUtils.copyProperties(entity,domain);
    domain.setEnable(YesNoEnum.get(entity.getEnable()));
    domain.setFirLevelName(FirLevelKind.get(entity.getFirLevelName()));
    domain.setSecLevelName(SecLevelKind.get(entity.getSecLevelName()));
    return domain;
  }

  @Override
  public MetaResourceDO convertEntity(MetaResourceDomain domain) {
    if(domain == null){
      return null;
    }
    MetaResourceDO entity = new MetaResourceDO();
    BeanUtils.copyProperties(domain,entity);
    entity.setEnable(domain.getEnable() == null ? null : domain.getEnable().getCode());
    entity.setFirLevelName(domain.getFirLevelName() == null ? null : domain.getFirLevelName().getCode());
    entity.setSecLevelName(domain.getSecLevelName() == null ? null : domain.getSecLevelName().getCode());
    return entity;
  }
}
